{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8aeeb4f6",
   "metadata": {},
   "source": [
    "# Build your Jupyter dashboard using Solara\n",
    "\n",
    "Welcome to the first part of a series of tutorials showing you how to create a dashboard in Jupyter and deploy it as a standalone web app. Importantly, you won't need to rewrite your app in a different framework for deployment. We will use a pure Python solution with no JavaScript or CSS required.\n",
    "\n",
    "Jupyter notebooks are an incredible data analysis tool since they blend code, visualization, and narrative into a single document. However, we do not want to show the code if the insights must be presented to a non-technical audience.\n",
    "\n",
    "\n",
    "Built on top of ipywidgets, the Solara framework integrates well into the Jupyter notebook, Jupyter lab as well as other Jupyter environments, and as we will see in a later article, can be deployed efficiently using the Solara server. This, by itself, makes Solara a perfect solution for creating dashboards or data apps.\n",
    "\n",
    "In this tutorial, we will create a simple dashboard using Solara's UI components. The final product will allow an end-user to filter,\n",
    "visualize and explore a dataset on a map.\n",
    "\n",
    "![image](https://dxhl76zpt6fap.cloudfront.net/public/docs/tutorial/jupyter-dashboard1.webp)\n",
    "\n",
    "## Pre-requisites \n",
    "\n",
    "You need to install `pandas`, `matplotlib`, `folium` and `solara`. Assuming you are using pip, you can execute on your shell:\n",
    "\n",
    "```\n",
    "$ pip install pandas matplotlib folium solara\n",
    "```\n",
    "\n",
    "\n",
    "Or in your notebook\n",
    "```\n",
    "%pip install pandas matplotlib folium solara\n",
    "```\n",
    "\n",
    "## The start\n",
    "\n",
    "We will use a subsample of the [San Fanfrisco crime dataset](https://www.kaggle.com/competitions/sf-crime/data) which contains information on types of crimes and where they were committed.\n",
    "\n",
    "[Download the CSV file](https://github.com/widgetti/solara/raw/master/solara/website/pages/documentation/getting_started/content/04-tutorials/SF_crime_sample.csv.gz) if you want to run this locally, or let the code below sort it out."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6cc6256a",
   "metadata": {},
   "source": [
    "The first thing we do when we read in the data is to print it out to see what the dataset contains."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4f399bdc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>IncidntNum</th>\n",
       "      <th>Category</th>\n",
       "      <th>Descript</th>\n",
       "      <th>DayOfWeek</th>\n",
       "      <th>Date</th>\n",
       "      <th>Time</th>\n",
       "      <th>PdDistrict</th>\n",
       "      <th>Resolution</th>\n",
       "      <th>Address</th>\n",
       "      <th>X</th>\n",
       "      <th>Y</th>\n",
       "      <th>Location</th>\n",
       "      <th>PdId</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>50820</td>\n",
       "      <td>160525689</td>\n",
       "      <td>BURGLARY</td>\n",
       "      <td>BURGLARY OF STORE, FORCIBLE ENTRY</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>06/28/2016 12:00:00 AM</td>\n",
       "      <td>21:25</td>\n",
       "      <td>TARAVAL</td>\n",
       "      <td>ARREST, BOOKED</td>\n",
       "      <td>600 Block of LINCOLN WY</td>\n",
       "      <td>-122.464850</td>\n",
       "      <td>37.765888</td>\n",
       "      <td>(37.7658875448653, -122.464850114297)</td>\n",
       "      <td>16052568905051</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11981</td>\n",
       "      <td>160334220</td>\n",
       "      <td>LARCENY/THEFT</td>\n",
       "      <td>PETTY THEFT FROM LOCKED AUTO</td>\n",
       "      <td>Friday</td>\n",
       "      <td>04/22/2016 12:00:00 AM</td>\n",
       "      <td>19:00</td>\n",
       "      <td>TARAVAL</td>\n",
       "      <td>NONE</td>\n",
       "      <td>SAN JOSE AV / LAKEVIEW AV</td>\n",
       "      <td>-122.450378</td>\n",
       "      <td>37.716169</td>\n",
       "      <td>(37.7161694707734, -122.450378171697)</td>\n",
       "      <td>16033422006243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>74626</td>\n",
       "      <td>160740053</td>\n",
       "      <td>LARCENY/THEFT</td>\n",
       "      <td>PETTY THEFT FROM A BUILDING</td>\n",
       "      <td>Monday</td>\n",
       "      <td>09/12/2016 12:00:00 AM</td>\n",
       "      <td>08:40</td>\n",
       "      <td>INGLESIDE</td>\n",
       "      <td>NONE</td>\n",
       "      <td>0 Block of PHELAN AV</td>\n",
       "      <td>-122.452290</td>\n",
       "      <td>37.725693</td>\n",
       "      <td>(37.7256933575703, -122.452289660492)</td>\n",
       "      <td>16074005306303</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>60776</td>\n",
       "      <td>160619721</td>\n",
       "      <td>WARRANTS</td>\n",
       "      <td>WARRANT ARREST</td>\n",
       "      <td>Monday</td>\n",
       "      <td>08/01/2016 12:00:00 AM</td>\n",
       "      <td>16:12</td>\n",
       "      <td>PARK</td>\n",
       "      <td>ARREST, BOOKED</td>\n",
       "      <td>1100 Block of SCOTT ST</td>\n",
       "      <td>-122.437099</td>\n",
       "      <td>37.780352</td>\n",
       "      <td>(37.7803522156893, -122.43709942832)</td>\n",
       "      <td>16061972163010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>34547</td>\n",
       "      <td>160345772</td>\n",
       "      <td>WARRANTS</td>\n",
       "      <td>ENROUTE TO OUTSIDE JURISDICTION</td>\n",
       "      <td>Wednesday</td>\n",
       "      <td>04/27/2016 12:00:00 AM</td>\n",
       "      <td>19:34</td>\n",
       "      <td>SOUTHERN</td>\n",
       "      <td>ARREST, BOOKED</td>\n",
       "      <td>600 Block of BRANNAN ST</td>\n",
       "      <td>-122.399841</td>\n",
       "      <td>37.775633</td>\n",
       "      <td>(37.7756327864282, -122.399841045579)</td>\n",
       "      <td>16034577262050</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9995</th>\n",
       "      <td>137465</td>\n",
       "      <td>170013301</td>\n",
       "      <td>OTHER OFFENSES</td>\n",
       "      <td>HARASSING PHONE CALLS</td>\n",
       "      <td>Saturday</td>\n",
       "      <td>11/26/2016 12:00:00 AM</td>\n",
       "      <td>12:00</td>\n",
       "      <td>SOUTHERN</td>\n",
       "      <td>NONE</td>\n",
       "      <td>1100 Block of MISSION ST</td>\n",
       "      <td>-122.412834</td>\n",
       "      <td>37.777790</td>\n",
       "      <td>(37.7777903094246, -122.412834332129)</td>\n",
       "      <td>17001330128135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9996</th>\n",
       "      <td>55811</td>\n",
       "      <td>160573939</td>\n",
       "      <td>OTHER OFFENSES</td>\n",
       "      <td>LOST/STOLEN LICENSE PLATE</td>\n",
       "      <td>Thursday</td>\n",
       "      <td>07/07/2016 12:00:00 AM</td>\n",
       "      <td>19:00</td>\n",
       "      <td>BAYVIEW</td>\n",
       "      <td>NONE</td>\n",
       "      <td>100 Block of TEXAS ST</td>\n",
       "      <td>-122.395812</td>\n",
       "      <td>37.764531</td>\n",
       "      <td>(37.7645312950153, -122.395812338479)</td>\n",
       "      <td>16057393971010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9997</th>\n",
       "      <td>120115</td>\n",
       "      <td>166110038</td>\n",
       "      <td>LARCENY/THEFT</td>\n",
       "      <td>GRAND THEFT FROM LOCKED AUTO</td>\n",
       "      <td>Saturday</td>\n",
       "      <td>05/14/2016 12:00:00 AM</td>\n",
       "      <td>03:30</td>\n",
       "      <td>CENTRAL</td>\n",
       "      <td>NONE</td>\n",
       "      <td>BAY ST / VANNESS AV</td>\n",
       "      <td>-122.425111</td>\n",
       "      <td>37.804146</td>\n",
       "      <td>(37.80414615262, -122.425110613231)</td>\n",
       "      <td>16611003806244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9998</th>\n",
       "      <td>5069</td>\n",
       "      <td>160093943</td>\n",
       "      <td>NON-CRIMINAL</td>\n",
       "      <td>AIDED CASE</td>\n",
       "      <td>Monday</td>\n",
       "      <td>02/01/2016 12:00:00 AM</td>\n",
       "      <td>15:23</td>\n",
       "      <td>TARAVAL</td>\n",
       "      <td>ARREST, BOOKED</td>\n",
       "      <td>2600 Block of SAN JOSE AV</td>\n",
       "      <td>-122.450635</td>\n",
       "      <td>37.715772</td>\n",
       "      <td>(37.7157715048394, -122.450634805259)</td>\n",
       "      <td>16009394351040</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9999</th>\n",
       "      <td>35667</td>\n",
       "      <td>160373212</td>\n",
       "      <td>ASSAULT</td>\n",
       "      <td>BATTERY</td>\n",
       "      <td>Friday</td>\n",
       "      <td>05/06/2016 12:00:00 AM</td>\n",
       "      <td>20:30</td>\n",
       "      <td>BAYVIEW</td>\n",
       "      <td>NONE</td>\n",
       "      <td>1300 Block of NEWHALL ST</td>\n",
       "      <td>-122.391880</td>\n",
       "      <td>37.735936</td>\n",
       "      <td>(37.7359364818345, -122.391879837176)</td>\n",
       "      <td>16037321204134</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10000 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Unnamed: 0  IncidntNum        Category  \\\n",
       "0          50820   160525689        BURGLARY   \n",
       "1          11981   160334220   LARCENY/THEFT   \n",
       "2          74626   160740053   LARCENY/THEFT   \n",
       "3          60776   160619721        WARRANTS   \n",
       "4          34547   160345772        WARRANTS   \n",
       "...          ...         ...             ...   \n",
       "9995      137465   170013301  OTHER OFFENSES   \n",
       "9996       55811   160573939  OTHER OFFENSES   \n",
       "9997      120115   166110038   LARCENY/THEFT   \n",
       "9998        5069   160093943    NON-CRIMINAL   \n",
       "9999       35667   160373212         ASSAULT   \n",
       "\n",
       "                               Descript  DayOfWeek                    Date  \\\n",
       "0     BURGLARY OF STORE, FORCIBLE ENTRY    Tuesday  06/28/2016 12:00:00 AM   \n",
       "1          PETTY THEFT FROM LOCKED AUTO     Friday  04/22/2016 12:00:00 AM   \n",
       "2           PETTY THEFT FROM A BUILDING     Monday  09/12/2016 12:00:00 AM   \n",
       "3                        WARRANT ARREST     Monday  08/01/2016 12:00:00 AM   \n",
       "4       ENROUTE TO OUTSIDE JURISDICTION  Wednesday  04/27/2016 12:00:00 AM   \n",
       "...                                 ...        ...                     ...   \n",
       "9995              HARASSING PHONE CALLS   Saturday  11/26/2016 12:00:00 AM   \n",
       "9996          LOST/STOLEN LICENSE PLATE   Thursday  07/07/2016 12:00:00 AM   \n",
       "9997       GRAND THEFT FROM LOCKED AUTO   Saturday  05/14/2016 12:00:00 AM   \n",
       "9998                         AIDED CASE     Monday  02/01/2016 12:00:00 AM   \n",
       "9999                            BATTERY     Friday  05/06/2016 12:00:00 AM   \n",
       "\n",
       "       Time PdDistrict      Resolution                    Address           X  \\\n",
       "0     21:25    TARAVAL  ARREST, BOOKED    600 Block of LINCOLN WY -122.464850   \n",
       "1     19:00    TARAVAL            NONE  SAN JOSE AV / LAKEVIEW AV -122.450378   \n",
       "2     08:40  INGLESIDE            NONE       0 Block of PHELAN AV -122.452290   \n",
       "3     16:12       PARK  ARREST, BOOKED     1100 Block of SCOTT ST -122.437099   \n",
       "4     19:34   SOUTHERN  ARREST, BOOKED    600 Block of BRANNAN ST -122.399841   \n",
       "...     ...        ...             ...                        ...         ...   \n",
       "9995  12:00   SOUTHERN            NONE   1100 Block of MISSION ST -122.412834   \n",
       "9996  19:00    BAYVIEW            NONE      100 Block of TEXAS ST -122.395812   \n",
       "9997  03:30    CENTRAL            NONE        BAY ST / VANNESS AV -122.425111   \n",
       "9998  15:23    TARAVAL  ARREST, BOOKED  2600 Block of SAN JOSE AV -122.450635   \n",
       "9999  20:30    BAYVIEW            NONE   1300 Block of NEWHALL ST -122.391880   \n",
       "\n",
       "              Y                               Location            PdId  \n",
       "0     37.765888  (37.7658875448653, -122.464850114297)  16052568905051  \n",
       "1     37.716169  (37.7161694707734, -122.450378171697)  16033422006243  \n",
       "2     37.725693  (37.7256933575703, -122.452289660492)  16074005306303  \n",
       "3     37.780352   (37.7803522156893, -122.43709942832)  16061972163010  \n",
       "4     37.775633  (37.7756327864282, -122.399841045579)  16034577262050  \n",
       "...         ...                                    ...             ...  \n",
       "9995  37.777790  (37.7777903094246, -122.412834332129)  17001330128135  \n",
       "9996  37.764531  (37.7645312950153, -122.395812338479)  16057393971010  \n",
       "9997  37.804146    (37.80414615262, -122.425110613231)  16611003806244  \n",
       "9998  37.715772  (37.7157715048394, -122.450634805259)  16009394351040  \n",
       "9999  37.735936  (37.7359364818345, -122.391879837176)  16037321204134  \n",
       "\n",
       "[10000 rows x 14 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "from pathlib import Path\n",
    "import solara\n",
    "\n",
    "ROOT = Path(solara.__file__).parent / \"website\" / \"pages\" / \"docs\" / \"content\" / \"04-tutorial\"\n",
    "path = ROOT / Path(\"SF_crime_sample.csv.gz\")\n",
    "url = \"https://github.com/widgetti/solara/raw/master/solara/website/pages/documentation/getting_started/content/04-tutorials/SF_crime_sample.csv.gz\"\n",
    "\n",
    "if path.exists():\n",
    "    df_crime = pd.read_csv(path)\n",
    "else:\n",
    "    df_crime = pd.read_csv(url)\n",
    "\n",
    "df_crime"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "08a9644a",
   "metadata": {},
   "source": [
    "The data looks clean, but since we will work with the `Category` and `PdDistrict` column data, let us convert those columns to title case."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f3373227",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>IncidntNum</th>\n",
       "      <th>Category</th>\n",
       "      <th>Descript</th>\n",
       "      <th>DayOfWeek</th>\n",
       "      <th>Date</th>\n",
       "      <th>Time</th>\n",
       "      <th>PdDistrict</th>\n",
       "      <th>Resolution</th>\n",
       "      <th>Address</th>\n",
       "      <th>X</th>\n",
       "      <th>Y</th>\n",
       "      <th>Location</th>\n",
       "      <th>PdId</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>50820</td>\n",
       "      <td>160525689</td>\n",
       "      <td>Burglary</td>\n",
       "      <td>BURGLARY OF STORE, FORCIBLE ENTRY</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>06/28/2016 12:00:00 AM</td>\n",
       "      <td>21:25</td>\n",
       "      <td>Taraval</td>\n",
       "      <td>ARREST, BOOKED</td>\n",
       "      <td>600 Block of LINCOLN WY</td>\n",
       "      <td>-122.464850</td>\n",
       "      <td>37.765888</td>\n",
       "      <td>(37.7658875448653, -122.464850114297)</td>\n",
       "      <td>16052568905051</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11981</td>\n",
       "      <td>160334220</td>\n",
       "      <td>Larceny/Theft</td>\n",
       "      <td>PETTY THEFT FROM LOCKED AUTO</td>\n",
       "      <td>Friday</td>\n",
       "      <td>04/22/2016 12:00:00 AM</td>\n",
       "      <td>19:00</td>\n",
       "      <td>Taraval</td>\n",
       "      <td>NONE</td>\n",
       "      <td>SAN JOSE AV / LAKEVIEW AV</td>\n",
       "      <td>-122.450378</td>\n",
       "      <td>37.716169</td>\n",
       "      <td>(37.7161694707734, -122.450378171697)</td>\n",
       "      <td>16033422006243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>74626</td>\n",
       "      <td>160740053</td>\n",
       "      <td>Larceny/Theft</td>\n",
       "      <td>PETTY THEFT FROM A BUILDING</td>\n",
       "      <td>Monday</td>\n",
       "      <td>09/12/2016 12:00:00 AM</td>\n",
       "      <td>08:40</td>\n",
       "      <td>Ingleside</td>\n",
       "      <td>NONE</td>\n",
       "      <td>0 Block of PHELAN AV</td>\n",
       "      <td>-122.452290</td>\n",
       "      <td>37.725693</td>\n",
       "      <td>(37.7256933575703, -122.452289660492)</td>\n",
       "      <td>16074005306303</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>60776</td>\n",
       "      <td>160619721</td>\n",
       "      <td>Warrants</td>\n",
       "      <td>WARRANT ARREST</td>\n",
       "      <td>Monday</td>\n",
       "      <td>08/01/2016 12:00:00 AM</td>\n",
       "      <td>16:12</td>\n",
       "      <td>Park</td>\n",
       "      <td>ARREST, BOOKED</td>\n",
       "      <td>1100 Block of SCOTT ST</td>\n",
       "      <td>-122.437099</td>\n",
       "      <td>37.780352</td>\n",
       "      <td>(37.7803522156893, -122.43709942832)</td>\n",
       "      <td>16061972163010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>34547</td>\n",
       "      <td>160345772</td>\n",
       "      <td>Warrants</td>\n",
       "      <td>ENROUTE TO OUTSIDE JURISDICTION</td>\n",
       "      <td>Wednesday</td>\n",
       "      <td>04/27/2016 12:00:00 AM</td>\n",
       "      <td>19:34</td>\n",
       "      <td>Southern</td>\n",
       "      <td>ARREST, BOOKED</td>\n",
       "      <td>600 Block of BRANNAN ST</td>\n",
       "      <td>-122.399841</td>\n",
       "      <td>37.775633</td>\n",
       "      <td>(37.7756327864282, -122.399841045579)</td>\n",
       "      <td>16034577262050</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9995</th>\n",
       "      <td>137465</td>\n",
       "      <td>170013301</td>\n",
       "      <td>Other Offenses</td>\n",
       "      <td>HARASSING PHONE CALLS</td>\n",
       "      <td>Saturday</td>\n",
       "      <td>11/26/2016 12:00:00 AM</td>\n",
       "      <td>12:00</td>\n",
       "      <td>Southern</td>\n",
       "      <td>NONE</td>\n",
       "      <td>1100 Block of MISSION ST</td>\n",
       "      <td>-122.412834</td>\n",
       "      <td>37.777790</td>\n",
       "      <td>(37.7777903094246, -122.412834332129)</td>\n",
       "      <td>17001330128135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9996</th>\n",
       "      <td>55811</td>\n",
       "      <td>160573939</td>\n",
       "      <td>Other Offenses</td>\n",
       "      <td>LOST/STOLEN LICENSE PLATE</td>\n",
       "      <td>Thursday</td>\n",
       "      <td>07/07/2016 12:00:00 AM</td>\n",
       "      <td>19:00</td>\n",
       "      <td>Bayview</td>\n",
       "      <td>NONE</td>\n",
       "      <td>100 Block of TEXAS ST</td>\n",
       "      <td>-122.395812</td>\n",
       "      <td>37.764531</td>\n",
       "      <td>(37.7645312950153, -122.395812338479)</td>\n",
       "      <td>16057393971010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9997</th>\n",
       "      <td>120115</td>\n",
       "      <td>166110038</td>\n",
       "      <td>Larceny/Theft</td>\n",
       "      <td>GRAND THEFT FROM LOCKED AUTO</td>\n",
       "      <td>Saturday</td>\n",
       "      <td>05/14/2016 12:00:00 AM</td>\n",
       "      <td>03:30</td>\n",
       "      <td>Central</td>\n",
       "      <td>NONE</td>\n",
       "      <td>BAY ST / VANNESS AV</td>\n",
       "      <td>-122.425111</td>\n",
       "      <td>37.804146</td>\n",
       "      <td>(37.80414615262, -122.425110613231)</td>\n",
       "      <td>16611003806244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9998</th>\n",
       "      <td>5069</td>\n",
       "      <td>160093943</td>\n",
       "      <td>Non-Criminal</td>\n",
       "      <td>AIDED CASE</td>\n",
       "      <td>Monday</td>\n",
       "      <td>02/01/2016 12:00:00 AM</td>\n",
       "      <td>15:23</td>\n",
       "      <td>Taraval</td>\n",
       "      <td>ARREST, BOOKED</td>\n",
       "      <td>2600 Block of SAN JOSE AV</td>\n",
       "      <td>-122.450635</td>\n",
       "      <td>37.715772</td>\n",
       "      <td>(37.7157715048394, -122.450634805259)</td>\n",
       "      <td>16009394351040</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9999</th>\n",
       "      <td>35667</td>\n",
       "      <td>160373212</td>\n",
       "      <td>Assault</td>\n",
       "      <td>BATTERY</td>\n",
       "      <td>Friday</td>\n",
       "      <td>05/06/2016 12:00:00 AM</td>\n",
       "      <td>20:30</td>\n",
       "      <td>Bayview</td>\n",
       "      <td>NONE</td>\n",
       "      <td>1300 Block of NEWHALL ST</td>\n",
       "      <td>-122.391880</td>\n",
       "      <td>37.735936</td>\n",
       "      <td>(37.7359364818345, -122.391879837176)</td>\n",
       "      <td>16037321204134</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10000 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Unnamed: 0  IncidntNum        Category  \\\n",
       "0          50820   160525689        Burglary   \n",
       "1          11981   160334220   Larceny/Theft   \n",
       "2          74626   160740053   Larceny/Theft   \n",
       "3          60776   160619721        Warrants   \n",
       "4          34547   160345772        Warrants   \n",
       "...          ...         ...             ...   \n",
       "9995      137465   170013301  Other Offenses   \n",
       "9996       55811   160573939  Other Offenses   \n",
       "9997      120115   166110038   Larceny/Theft   \n",
       "9998        5069   160093943    Non-Criminal   \n",
       "9999       35667   160373212         Assault   \n",
       "\n",
       "                               Descript  DayOfWeek                    Date  \\\n",
       "0     BURGLARY OF STORE, FORCIBLE ENTRY    Tuesday  06/28/2016 12:00:00 AM   \n",
       "1          PETTY THEFT FROM LOCKED AUTO     Friday  04/22/2016 12:00:00 AM   \n",
       "2           PETTY THEFT FROM A BUILDING     Monday  09/12/2016 12:00:00 AM   \n",
       "3                        WARRANT ARREST     Monday  08/01/2016 12:00:00 AM   \n",
       "4       ENROUTE TO OUTSIDE JURISDICTION  Wednesday  04/27/2016 12:00:00 AM   \n",
       "...                                 ...        ...                     ...   \n",
       "9995              HARASSING PHONE CALLS   Saturday  11/26/2016 12:00:00 AM   \n",
       "9996          LOST/STOLEN LICENSE PLATE   Thursday  07/07/2016 12:00:00 AM   \n",
       "9997       GRAND THEFT FROM LOCKED AUTO   Saturday  05/14/2016 12:00:00 AM   \n",
       "9998                         AIDED CASE     Monday  02/01/2016 12:00:00 AM   \n",
       "9999                            BATTERY     Friday  05/06/2016 12:00:00 AM   \n",
       "\n",
       "       Time PdDistrict      Resolution                    Address           X  \\\n",
       "0     21:25    Taraval  ARREST, BOOKED    600 Block of LINCOLN WY -122.464850   \n",
       "1     19:00    Taraval            NONE  SAN JOSE AV / LAKEVIEW AV -122.450378   \n",
       "2     08:40  Ingleside            NONE       0 Block of PHELAN AV -122.452290   \n",
       "3     16:12       Park  ARREST, BOOKED     1100 Block of SCOTT ST -122.437099   \n",
       "4     19:34   Southern  ARREST, BOOKED    600 Block of BRANNAN ST -122.399841   \n",
       "...     ...        ...             ...                        ...         ...   \n",
       "9995  12:00   Southern            NONE   1100 Block of MISSION ST -122.412834   \n",
       "9996  19:00    Bayview            NONE      100 Block of TEXAS ST -122.395812   \n",
       "9997  03:30    Central            NONE        BAY ST / VANNESS AV -122.425111   \n",
       "9998  15:23    Taraval  ARREST, BOOKED  2600 Block of SAN JOSE AV -122.450635   \n",
       "9999  20:30    Bayview            NONE   1300 Block of NEWHALL ST -122.391880   \n",
       "\n",
       "              Y                               Location            PdId  \n",
       "0     37.765888  (37.7658875448653, -122.464850114297)  16052568905051  \n",
       "1     37.716169  (37.7161694707734, -122.450378171697)  16033422006243  \n",
       "2     37.725693  (37.7256933575703, -122.452289660492)  16074005306303  \n",
       "3     37.780352   (37.7803522156893, -122.43709942832)  16061972163010  \n",
       "4     37.775633  (37.7756327864282, -122.399841045579)  16034577262050  \n",
       "...         ...                                    ...             ...  \n",
       "9995  37.777790  (37.7777903094246, -122.412834332129)  17001330128135  \n",
       "9996  37.764531  (37.7645312950153, -122.395812338479)  16057393971010  \n",
       "9997  37.804146    (37.80414615262, -122.425110613231)  16611003806244  \n",
       "9998  37.715772  (37.7157715048394, -122.450634805259)  16009394351040  \n",
       "9999  37.735936  (37.7359364818345, -122.391879837176)  16037321204134  \n",
       "\n",
       "[10000 rows x 14 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_crime[\"Category\"] = df_crime[\"Category\"].str.title()\n",
    "df_crime[\"PdDistrict\"] = df_crime[\"PdDistrict\"].str.title()\n",
    "df_crime"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62df988f",
   "metadata": {},
   "source": [
    "Using proper software engineering practices, we write a function that filters a dataframe to contain only the rows that match our chosen districts and categories."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a7d17a84",
   "metadata": {},
   "outputs": [],
   "source": [
    "def crime_filter(df, district_values, category_values):\n",
    "    df_dist = df.loc[df[\"PdDistrict\"].isin(district_values)]\n",
    "    df_category = df_dist.loc[df_dist[\"Category\"].isin(category_values)]\n",
    "    return df_category\n",
    "\n",
    "\n",
    "dff_crime = crime_filter(df_crime, [\"Bayview\", \"Northern\"], [\"Vandalism\", \"Assault\", \"Robbery\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b0e37cb4",
   "metadata": {},
   "source": [
    "Now, with our filtered dataset, we create two bar charts. We use regular Pandas and Matplotlib, but Seaborn or Plotly would also be appropriate choices."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3254c59d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAABIQAAAJOCAYAAADGcdzeAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAAsTAAALEwEAmpwYAAA0EElEQVR4nO3de7xtZV0v/s9XwLuFCBG3pJJfRaWkO7LSpOyUaAV1DCVLNI/kOdrVLlin1MqkU2o/KzU1A0tRSk1SM5U09OSlrZLiLUkhQC5bEAXv4vf8McaSyWLtvde+rL3W5nm/X6/5WnM+4/aMMcea45mfMZ4xq7sDAAAAwDhutd4VAAAAAGDPEggBAAAADEYgBAAAADAYgRAAAADAYARCAAAAAIMRCAEAAAAMRiAEu0lN/qqqPlFV79iN872+qr5hJ6d9X1Udtxvq8IiqesuuzmcEVXVRVf3getcDAEahDba+quo5VfXb67DcdW9zVdVxVXXpLs7jH6vqlN1Un/tW1Yd2x7wYg0CIPaaq3jQfqG+z3nVZyW444N4nyX9Lcnh3H7uVZRxSVX9ZVZdX1XVV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[
       "<Figure size 1440x720 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "\n",
    "def crime_charts(df):\n",
    "    cat_unique = df[\"Category\"].value_counts()\n",
    "    cat_unique = cat_unique.reset_index()\n",
    "\n",
    "    dist_unique = df[\"PdDistrict\"].value_counts()\n",
    "    dist_unique = dist_unique.reset_index()\n",
    "\n",
    "    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(20, 10))\n",
    "\n",
    "    ax1.bar(cat_unique[\"Category\"], cat_unique[\"count\"])\n",
    "    ax1.set_title(\"Amount of Criminal Case Based on Category\")\n",
    "    ax2.bar(dist_unique[\"PdDistrict\"], dist_unique[\"count\"])\n",
    "    ax2.set_title(\"Amount of Criminal Case in Selected District\")\n",
    "\n",
    "    display(fig)\n",
    "    plt.close(fig)\n",
    "\n",
    "\n",
    "crime_charts(dff_crime)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e71ff2f",
   "metadata": {},
   "source": [
    "Since we do not need bidirectional communication (e.g., we do not need to receive events or data from our map), we use Folium to display the locations of the committed crimes on a map. If we do need bidirectional communication, we can also decide to use [ipyleaflet](https://ipyleaflet.readthedocs.io/).\n",
    "\n",
    "Since we cannot display all the data on the map without crashing your browser, we limit it to a maximum of 50 points."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "82f1d2f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "import folium\n",
    "import folium.plugins\n",
    "\n",
    "\n",
    "def crime_map(df):\n",
    "    latitude = 37.77\n",
    "    longitude = -122.42\n",
    "\n",
    "    sanfran_map = folium.Map(location=[latitude, longitude], zoom_start=12)\n",
    "\n",
    "    incidents = folium.plugins.MarkerCluster().add_to(sanfran_map)\n",
    "\n",
    "    # loop through the dataframe and add each data point to the mark cluster\n",
    "    for (\n",
    "        lat,\n",
    "        lng,\n",
    "        label,\n",
    "    ) in zip(df.Y, df.X, df.Category):\n",
    "        folium.Marker(\n",
    "            location=[lat, lng],\n",
    "            icon=None,\n",
    "            popup=label,\n",
    "        ).add_to(incidents)\n",
    "\n",
    "    # show map\n",
    "    display(sanfran_map)\n",
    "\n",
    "\n",
    "crime_map(dff_crime.iloc[0:50, :])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b74914fd",
   "metadata": {},
   "source": [
    "## Making our first reactive visualization\n",
    "\n",
    "The above code works nicely, but if we want to explore different types of crimes, we need to modify and run all cells that determine our output manually. Would it not be much better to have a UI with controls determining the filtering and a view displaying the filtered data interactively?\n",
    "\n",
    "Let's start by importing the solara package and creating three reactive variables."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e7ea361",
   "metadata": {},
   "outputs": [],
   "source": [
    "import solara\n",
    "\n",
    "districts = solara.reactive([\"Bayview\", \"Northern\"])\n",
    "categories = solara.reactive([\"Vandalism\", \"Assault\", \"Robbery\"])\n",
    "limit = solara.reactive(100)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28622c20",
   "metadata": {},
   "source": [
    "A reactive variable is a container around a value (like an int, string, or list) that allows the UI to listen to changes automatically. Any change to your_reactive_variable.value will be picked up by Solara components that use them so that they can automatically redraw or update themselves.\n",
    "\n",
    "Let us now create our first component (View), which filters the data based on the reactive variables and shows the map and the charts. Solara supports the display mechanism of Jupyter so that we can use our previously defined functions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56055643",
   "metadata": {},
   "outputs": [],
   "source": [
    "@solara.component\n",
    "def View():\n",
    "    dff = crime_filter(df_crime, districts.value, categories.value)\n",
    "    row_count = len(dff)\n",
    "    if row_count > limit.value:\n",
    "        solara.Warning(f\"Only showing the first {limit.value} of {row_count:,} crimes on map\")\n",
    "    crime_map(dff.iloc[: limit.value])\n",
    "    if row_count > 0:\n",
    "        crime_charts(dff)\n",
    "    else:\n",
    "        solara.Warning(\"You filtered out all the data, no charts shown\")\n",
    "\n",
    "\n",
    "View()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b05c1db",
   "metadata": {},
   "source": [
    "Note that some UI parts (like the warning and the charts) are conditional. Solara will automatically find out what to add, remove, or update without you having to do this manually. Solara is declarative (similar to ReactJS) but also reactive. If we change the reactive variables, Solara will see those changes and notify the component instances that use its value.\n",
    "\n",
    "If we run the next lines of code in our notebook, our View will automatically update."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fef5d187",
   "metadata": {},
   "outputs": [],
   "source": [
    "limit.value = 70\n",
    "districts.value = [\"Soutern\", \"Northern\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8822d100",
   "metadata": {},
   "source": [
    "We can now explore our data much faster since we don't need to re-run the cells that depend on it.\n",
    "\n",
    "Solara's reactive and declarative nature makes it scalable to much larger applications than regular ipywidgets, where keeping the UI in sync and adding, removing, and updating widgets is a manual and bug-prone process."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "917a1501",
   "metadata": {},
   "source": [
    "## Adding controls\n",
    "\n",
    "We created a declarative and reactive mini app in our notebook, but we still need to manually modify the values by executing a code cell in our Notebook. Now, let us create a UI to control it. All Solara input components support reactive variables. This means that controlling a reactive variable using a UI element is often a one-liner."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c78010ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "solara.SelectMultiple(\"District\", all_values=[str(k) for k in df_crime[\"PdDistrict\"].unique().tolist()], values=districts)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74484e0c",
   "metadata": {},
   "source": [
    "Whow, that was simple! We can now easily change the filter and see the results update. Lets do this for all our reactive variables, and put them into a single component."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18290364",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "@solara.component\n",
    "def Controls():\n",
    "    solara.SelectMultiple(\"District\", all_values=[str(k) for k in df_crime[\"PdDistrict\"].unique().tolist()], values=districts)\n",
    "    solara.SelectMultiple(\"Category\", all_values=[str(k) for k in df_crime[\"Category\"].unique().tolist()], values=categories)\n",
    "    solara.Text(\"Maximum number of rows to show on map\")\n",
    "    solara.SliderInt(\"\", value=limit, min=1, max=1000)\n",
    "\n",
    "\n",
    "Controls()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0c1ac606",
   "metadata": {},
   "source": [
    "Note that the reactive variables are bi-directional, meaning that if you change it in the UI elements, it gets reflected on the Python code!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ca68fe8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Note that we can read AND write reactive variables\n",
    "categories.value = [*categories.value, \"Warrants\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5af8e2b8",
   "metadata": {},
   "source": [
    "## The final dashboard\n",
    "\n",
    "We now have two parts of our UI in separate cells. This can be an amazing experience when developing in a notebook, as it flows naturally in the data exploration process while writing your notebook.\n",
    "\n",
    "However, your end user will probably want something more coherent. The components we created are perfectly reusable, so we put them together in a single UI."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "af686391",
   "metadata": {},
   "outputs": [],
   "source": [
    "@solara.component\n",
    "def Page():\n",
    "    with solara.Sidebar():\n",
    "        Controls()\n",
    "    View()\n",
    "\n",
    "\n",
    "Page()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e07fd010",
   "metadata": {},
   "source": [
    "## Conclusions\n",
    "\n",
    "Using Solara, you created an interactive dashboard within a Jupyter notebook. Your Solara components are declarative, and when using reactive variables also reactive. Whether you change a reactive variables via code or the UI elements, your visualizations and map update automatically.\n",
    "\n",
    "Your dashboard prototype now runs in your Jupyter notebook environment, but we still have a few steps to we want to take. In our next tutorial, we will focus on deploying our notebook, without making any code changes. In our third tutorial we will expand our dashboard with a few more components and focus on creating a more advanced layout.\n",
    "\n",
    "\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
